package com.panghl.controller;

import com.panghl.entity.User;
import com.panghl.service.AnnoService;
import com.panghl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author panghl
 * @Date 2022/2/16
 **/
@RestController
@RequestMapping("")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private AnnoService annoService;

    /**
     * 手动操作RedisCache
     * @param id
     * @return
     */
    @GetMapping("/getCacheUserId")
    public User getCacheUserId(Integer id){
        return userService.getById(id);
    }

    @GetMapping("/testCacheable")
    public User testCacheable(Integer id){
        return annoService.getById(id);
    }

    @DeleteMapping("/testCacheEvict")
    public void delAnnoCacheId(Integer id){
        annoService.deleteUserById(id);
    }


    @PostMapping("/testCachePut")
    public void testCachePut(@RequestBody User user){
        annoService.add(user);
    }

    @PostMapping("/testCaching")
    public void testCaching(@RequestBody User user){
        annoService.createUser(user);
    }
}
